<!--
 * @FilePath     : /layui/demo/1569.html
 * @Description  : 给多选赋值
 * @Date         : 2025-02-24 15:25
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-02-24 15:26
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div id="demo1" class="xm-select-demo"></div>
    <br />
    <br />
    <button class="btn" id="demo1-test1">赋值张三</button>
    <button class="btn" id="demo1-test2">赋值张三(value方式)</button>
    <button class="btn" id="demo1-test3">追加赋值李四</button>
    <br />
    <br />
    <button class="btn" id="demo1-test4">清除李四</button>
    <button class="btn" id="demo1-test5">清空</button>
    <pre id="demo1-result"></pre>

    <script src="/xm-select/dist/xm-select.js"></script>
    <script>
      var demo1 = xmSelect.render({
        el: '#demo1',
        data: [
          { name: '张三', value: 1 },
          { name: '李四', value: 2 },
          { name: '王五', value: 3 },
        ],
      })

      /*
      动态赋值多选中的数据，参数 array 可以是 value 数组，也可以是完整的 object 数组。
      */

      document.getElementById('demo1-test1').onclick = function () {
        demo1.setValue([{ name: '张三', value: 1 }]) // 子项为 object 格式
      }


      // 子项为 value 数组模式
      document.getElementById('demo1-test2').onclick = function () {
        demo1.setValue([1])
      }

      document.getElementById('demo1-test3').onclick = function () {
        demo1.append([2])
      }

      document.getElementById('demo1-test4').onclick = function () {
        demo1.delete([2])
      }

      document.getElementById('demo1-test5').onclick = function () {
        demo1.setValue([])
      }
    </script>
  </body>
</html>
